<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>未审批产品列表---供应商</title>
    <script type="text/javascript">
      var rejectProductWin;
      var productViewWin;
      var productId;
      Ext.onReady(function(){
        //产品列表---------------------------------------------------------
        //生成有关客户的Grid
        var productDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: pageSize
          },
          proxy: new Ext.data.HttpProxy({
            url: '/product/getProductsForAuditor'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'name'
            }, {
              name: 'vendor_name',
              mapping: 'vendor.company_name'
            },{
              name: 'model'
            }, {
              name: 'specification'
            }, {
              name: 'manufacturer'
            }, {
              name: 'unit_price'
            }, {
              name: 'brand'
            },{
              name: 'auditing_status'
            }])
        });
        var productSM = new Ext.grid.CheckboxSelectionModel();
        var productCM = new Ext.grid.ColumnModel([
          new Ext.grid.RowNumberer(),
          productSM,
          {
            header: '产品名称',
            dataIndex: 'name',
            width:180
          }, {
            header: '供应商',
            dataIndex: 'vendor_name',
            width:180
          },{
            header: '品牌',
            dataIndex: 'brand',
            width:60
          }, {
            header: '型号',
            dataIndex: 'model',
            width:130
          }, {
            header: '规格',
            dataIndex: 'specification',
            width:80
          }, {
            header: '生产商',
            dataIndex: 'manufacturer',
            width:130
          }, {
            header: '单价',
            dataIndex: 'unit_price',
            sortable:true,
            width:60
          },  {
            header: '审批状态',
            dataIndex: 'auditing_status',
            renderer:auditingRender,
            width:80
          }]);
        var productForAuditorGrid =  new Ext.grid.GridPanel({
          ds: productDS,
          cm: productCM,
          sm: productSM,
          width: screenWidth-390,
          height: screenHeight-480,
          iconCls: 'icon-grid',loadMask: true,
          //collapsible: true,
          //animCollapse: false,
          //frame: true,
          //title: '客户列表',
          tbar:['-',
            {
            text: '查看产品',
            width:50,
            iconCls:'editItem',
            handler:function(){
                var records = productForAuditorGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请先选中一条记录后，再编辑。');
                }else{
                  //把表单添加到窗口中
                  productId = records[0].get('id');
                  productViewWin = new Ext.Window({
                    title: '查看产品信息',
                    layout:'fit',
                    width:617,
                    height:440,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    //autoScroll:true,
                    autoLoad: {
                      url: "/product/productView?id=" + productId,
                      scripts: true
                    }
                  });
                  productViewWin.on("destroy",function(){
                    productDS.reload();
                  });
                  productViewWin.resizable = false;
                  productViewWin.show();
                }
            }
          },{
              text:'通过产品',
              width:50,
              iconCls: 'yes',
              handler:function(){
                if(productForAuditorGrid.getSelectionModel().hasSelection()){
                            var rs=productForAuditorGrid.getSelectionModel().getSelections();
                            var ids=[];
                            var name='';
                            for(var i=0;i<rs.length;i++){
                                var data=rs[i].data;
                                ids.push(data.id);
                                name+=data.name+'<br>';
                            }
                            var keys=Ext.util.JSON.encode(ids);
                            Ext.MessageBox.confirm('警告','确定审批通过以下产品？<br><font color="red">' + name + '</font>',function (button){
                                if(button=='yes'){
                                  Ext.Ajax.request({
                                        url:'/product/auditProduct',
                                        method:'post',
                                        success:function(response,opts){
                                            var data = Ext.util.JSON.decode(response.responseText);
                                            if(data.success&&data.info=='success') {
                                                 productDS.reload();
                                                 Ext.Msg.alert('提示信息', '已成功审批通过产品。');
                                            } else {
                                                 Ext.Msg.alert('提示信息', data.info);
                                            }
                                        },
                                        params: {"id":keys}
                                    });
                                }
                            });
                 }else{
                    Ext.Msg.alert('提示信息','请选择要通过审批的产品');
                 }
              }
            },{
              text:'驳回产品',
              width:50,
              iconCls: 'no',
              handler:function(){
                if(productForAuditorGrid.getSelectionModel().hasSelection()){
                            var rs=productForAuditorGrid.getSelectionModel().getSelections();
                            var ids=[];
                            var name='';
                            for(var i=0;i<rs.length;i++){
                                var data=rs[i].data;
                                ids.push(data.id);
                                name+=data.name+'<br>';
                            }
                            var keys=Ext.util.JSON.encode(ids);
                            rejectProductWin = new Ext.Window({
                              title: '驳回产品',
                              layout:'fit',
                              width: 417,
                              height: 150,
                              closeAction:'destroy',
                              constrain:true,
                              plain: true,
                              modal: true,
                              autoLoad: {
                                url: "/product/rejectReason?id=" + keys,
                                scripts: true
                              }
                            });
                            rejectProductWin.on("destroy",function(){
                              productDS.reload();
                            });
                            rejectProductWin.resizable = false;
                            rejectProductWin.show();
                 }else{
                    Ext.Msg.alert('提示信息','请选择要驳回的产品');
                 }
              }
            },'-','检索条件','-',
            '产品名称',
            new Ext.form.TextField({
                name: 'product_name',
                width:150,
                id: 'product_name'
             }),
             '供应商名称',
             new Ext.form.TextField({
                name: 'vendor_name',
                width:150,
                id: 'vendor_name'
             }),
             {
                text:'搜索',
                iconCls:'search',
                handler:function(){

                  productDS.baseParams.product_name = Ext.get('product_name').dom.value
                  productDS.baseParams.vendor_name = Ext.get('vendor_name').dom.value
                  productDS.load({
                    params:{
                      start: 0,
                      limit: pageSize
                    }
                  })
                }
              }
          ],
          bbar: new Ext.PagingToolbar({
            pageSize: pageSize,
            store: productDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });
        productForAuditorGrid.render('product_auditor_list');
        productDS.load();
      })
    </script>
  </head>
  <body>
    <div id="product_auditor_list"></div>
  </body>
</html>
